<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "org.json.simple.*, java.util.TreeMap, com.classes.Casemast,java.util.ArrayList" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%
int case_id = Integer.parseInt(request.getAttribute("case_id").toString());
TreeMap<String, String> viewAccess = (TreeMap<String, String>) request.getAttribute("view_access");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="include/html-meta.jsp" />
<title>MAYBANK</title>
<script src="<%= request.getContextPath() %>/js/merchant.js"></script>
</head>

<body>

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->

<div class="row-fluid page">
	<div class="span12">

		<jsp:include page="include/tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("document") %>' />
		</jsp:include>
		
		<jsp:include page="/jsp/map/include/document-tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("document_upload") %>' />
		</jsp:include>
		
		<div class="form-horizontal other-main-content">
			<form name="doc_upload" method="post" enctype="multipart/form-data" action="<%= request.getContextPath() %>/NewApp.do?dispatch=supporting_document_upload&m_id=<%= EncryptionHelper.encryptEncodeURL(request.getAttribute("merchant_id")+"") %>&c_id=<%= EncryptionHelper.encryptEncodeURL(request.getAttribute("case_id")+"") %>">
				<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
				<div class="row-fluid">
					<div class="span8">
						
						<div class="control-group">
							<label class="control-label">File</label>
							<div class="controls">
								<input type="file" name="upfile">
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label">MAP Reference No.</label>
							<div class="controls">
								<input type="text" name="ref_no">
								
								<%
								Casemast m_case = (Casemast) request.getAttribute("m_case");
								if(m_case.getLastReferenceNo().length() > 0){
									out.println("<span style=\"display:inline-block; background-color:#0088cc; color:#fff; font-weight:bold; line-height: 20px; padding: 4px 12px;\">" + m_case.getLastReferenceNo() + "</span>");
								}
								%>
							</div>
						</div>
					</div>
					
					<div class="span4">
						<button name="doc_submit" class="btn" type="submit">Add Attachment</button>
					</div>
				</div>
			</form>
			
			<div class="row-fluid">
				<div class="span12">
					
					<table class="tbl" style="margin:10px 0px 30px 0px">
						<tr style="background-color:#eee">
							<th style="width:55%; text-align:left">File Name</th>
							<th style="width:15%">Ref No.</th>
							<th style="width:10%">By</th>
							<th style="width:10%">Date</th>
							<th style="width:10%"></th>
						</tr>
						<%
							ArrayList<TreeMap<String, String>> docArr = ((Casemast) request.getAttribute("m_case")).getDocuments();
							if(docArr != null){
								for(TreeMap<String, String> docLog : docArr){
									String doc_name = docLog.get("name");
									if(viewAccess.get("download_document").equals("edit")){
										String c_id = request.getAttribute("case_id").toString();
										doc_name = "<a href=\"" + request.getContextPath() + "/NewApp.do?dispatch=supporting_document_download&m_id=" + request.getAttribute("merchant_id") + "&c_id=" + EncryptionHelper.encryptEncodeURL(c_id) + "&doc_id=" + docLog.get("id") + "\">" + docLog.get("name") + "</a>";
									}
									
									String html = "<tr>"
									+ "	<td>" + doc_name + "</td>"
									+ "	<td>" + (docLog.get("ref_no") == null ? "" : docLog.get("ref_no")) + "</td>"
									+ "	<td>" + docLog.get("created_by") + "</td>"
									+ "	<td>" + Casemast.formatCreatedDate("dd/MM/yyyy HH:mm", Long.parseLong(docLog.get("created_date"))) + "</td>"
									+ "<td><a href=\"javascript:merchant.document_delete('" + EncryptionHelper.encrypt(request.getAttribute("case_id")+"") + "', '" + EncryptionHelper.encrypt(request.getAttribute("merchant_id")+"") + "', '" + EncryptionHelper.encrypt(docLog.get("id")) + "')\">Delete</a></td>"
									+ "</tr>";
									
									out.println(html);
								}
							}
						%>
					</table>
					
					<% 
					String best_practice = ((Casemast) request.getAttribute("m_case")).getBestPractice();
					System.out.println("best_practice:" + best_practice);
					String html = "<form name=\"form1\">"
						+ "	<label class=\"radio\"><input name=\"best_practice\" type=\"radio\" value=\"Best Practice for E-Commerce Merchant\" />Best Practice for E-Commerce Merchant</label>"
						+ "	<label class=\"radio\"><input name=\"best_practice\" type=\"radio\" value=\"Best Practice for Recurring Payment System (RPS) Merchant\" />Best Practice for Recurring Payment System (RPS) Merchant</label>"
						+ "	<label class=\"radio\"><input name=\"best_practice\" type=\"radio\" value=\"Best Practice for Mail Order Telephone Order (MO/TO) Merchant\" />Best Practice for Mail Order Telephone Order (MO/TO) Merchant</label>"
						+ "	<label class=\"radio\"><input name=\"best_practice\" type=\"radio\" value=\"Best Practice for EzyPayment Merchant\" />Best Practice for EzyPayment Merchant</label>"
						+ "	<label class=\"radio\"><input name=\"best_practice\" type=\"radio\" value=\"None\" />None</label>"
						+ "</form>";
					
					html = html.replace("value=\"" + best_practice + "\"", "value=\"" + best_practice + "\" checked ");
					out.println(html);
					%>
					
					
				</div>
		
			</div>
		</div>

		
		<div class="row-fluid">
			<div class="span12 btn-control">
				<button type="submit" id="submit" class="btn" onclick="merchant.best_practice('<%=EncryptionHelper.encrypt(case_id+"") %>')">Save</button>
			</div>
		</div>

	</div>
</div>


<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->


</body>
</html>